import { watch, ref } from 'vue'

import type { FormFields } from '../type'

export const useFormFields = <T extends Record<string, any>>(props: T) => {
  const showFields = ref<FormFields[]>([])

  watch(
    () => props.fields,
    () => {
      // 过滤 动态显示 隐藏
      showFields.value = props.fields.filter(
        (field: FormFields) => field.show !== true
      )
    },
    {
      deep: true,
      immediate: true
    }
  )

  return {
    showFields
  }
}
